From 391736c0812b301beefe05f96c4c937996b7ba40 Mon Sep 17 00:00:00 2001 From: Daniel Friesen Date: Thu, 15 Sep 2011 15:19:49 +0000 Subject: [PATCH] Use IContextSource instead of RequestContext inside type hints and instanceof checks. All we need is something that implements IContextSource and it's possible we may want to implement types of RequestContext that don't directly extend RequestContext but are perfectly valid to be passed to classes. --- includes/Action.php | 10 +++++----- includes/Article.php | 12 ++++++------ includes/ChangesList.php | 8 ++++---- includes/HTMLForm.php | 12 ++++++------ includes/OutputPage.php | 2 +- includes/Preferences.php | 4 ++-- includes/RequestContext.php | 12 ++++++------ includes/RevisionList.php | 6 +++--- includes/SpecialPage.php | 12 ++++++------ includes/SpecialPageFactory.php | 8 ++++---- includes/Wiki.php | 8 ++++---- includes/logging/LogFormatter.php | 4 ++-- includes/revisiondelete/RevisionDeleteAbstracts.php | 2 +- includes/specials/SpecialUpload.php | 2 +- 14 files changed, 51 insertions(+), 51 deletions(-) diff --git a/includes/Action.php b/includes/Action.php index e836098870..b165721e69 100644 --- a/includes/Action.php +++ b/includes/Action.php @@ -32,8 +32,8 @@ abstract class Action { protected $page; /** - * RequestContext if specified; otherwise we'll use the Context from the Page - * @var RequestContext + * IContextSource if specified; otherwise we'll use the Context from the Page + * @var IContextSource */ protected $context; @@ -96,11 +96,11 @@ abstract class Action { } /** - * Get the RequestContext in use here - * @return RequestContext + * Get the IContextSource in use here + * @return IContextSource */ protected final function getContext() { - if ( $this->context instanceof RequestContext ) { + if ( $this->context instanceof IContextSource ) { return $this->context; } return $this->page->getContext(); diff --git a/includes/Article.php b/includes/Article.php index e453b37a69..3dcef85a52 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -23,7 +23,7 @@ class Article extends Page { */ /** - * @var RequestContext + * @var IContextSource */ protected $mContext; @@ -88,10 +88,10 @@ class Article extends Page { * Create an Article object of the appropriate class for the given page. * * @param $title Title - * @param $context RequestContext + * @param $context IContextSource * @return Article object */ - public static function newFromTitle( $title, RequestContext $context ) { + public static function newFromTitle( $title, IContextSource $context ) { if ( NS_MEDIA == $title->getNamespace() ) { // FIXME: where should this go? $title = Title::makeTitle( NS_FILE, $title->getDBkey() ); @@ -1856,7 +1856,7 @@ class Article extends Page { /** * Sets the context this Article is executed in * - * @param $context RequestContext + * @param $context IContextSource * @since 1.18 */ public function setContext( $context ) { @@ -1866,11 +1866,11 @@ class Article extends Page { /** * Gets the context this Article is executed in * - * @return RequestContext + * @return IContextSource * @since 1.18 */ public function getContext() { - if ( $this->mContext instanceof RequestContext ) { + if ( $this->mContext instanceof IContextSource ) { return $this->mContext; } else { wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" ); diff --git a/includes/ChangesList.php b/includes/ChangesList.php index bb36ce999b..fe40cd49d6 100644 --- a/includes/ChangesList.php +++ b/includes/ChangesList.php @@ -45,10 +45,10 @@ class ChangesList extends ContextSource { /** * Changeslist contructor * - * @param $obj Skin or RequestContext + * @param $obj Skin or IContextSource */ public function __construct( $obj ) { - if ( $obj instanceof RequestContext ) { + if ( $obj instanceof IContextSource ) { $this->setContext( $obj ); $this->skin = $obj->getSkin(); } else { @@ -74,10 +74,10 @@ class ChangesList extends ContextSource { * Fetch an appropriate changes list class for the specified context * Some users might want to use an enhanced list format, for instance * - * @param $context RequestContext to use + * @param $context IContextSource to use * @return ChangesList|EnhancedChangesList|OldChangesList derivative */ - public static function newFromContext( RequestContext $context ) { + public static function newFromContext( IContextSource $context ) { $user = $context->getUser(); $sk = $context->getSkin(); $list = null; diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php index da84fc30e2..c8279bcf03 100644 --- a/includes/HTMLForm.php +++ b/includes/HTMLForm.php @@ -102,7 +102,7 @@ class HTMLForm { protected $mSubmitText; protected $mSubmitTooltip; - protected $mContext; // setTitle() * @param $messagePrefix String a prefix to go in front of default messages */ - public function __construct( $descriptor, /*RequestContext*/ $context = null, $messagePrefix = '' ) { - if( $context instanceof RequestContext ){ + public function __construct( $descriptor, /*IContextSource*/ $context = null, $messagePrefix = '' ) { + if( $context instanceof IContextSource ){ $this->mContext = $context; $this->mTitle = false; // We don't need them to set a title $this->mMessagePrefix = $messagePrefix; @@ -638,10 +638,10 @@ class HTMLForm { } /** - * @return RequestContext + * @return IContextSource */ public function getContext(){ - return $this->mContext instanceof RequestContext + return $this->mContext instanceof IContextSource ? $this->mContext : RequestContext::getMain(); } diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 7760d15454..8a97061baa 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -223,7 +223,7 @@ class OutputPage extends ContextSource { * Instead a new RequestContext should be created and it will implicitly create * a OutputPage tied to that context. */ - function __construct( RequestContext $context = null ) { + function __construct( IContextSource $context = null ) { if ( $context === null ) { # Extensions should use `new RequestContext` instead of `new OutputPage` now. wfDeprecated( __METHOD__ ); diff --git a/includes/Preferences.php b/includes/Preferences.php index 9f4e5b2f42..a955b6fb5d 100644 --- a/includes/Preferences.php +++ b/includes/Preferences.php @@ -1212,11 +1212,11 @@ class Preferences { /** * @param $user User - * @param $context RequestContext + * @param $context IContextSource * @param $formClass string * @return HtmlForm */ - static function getFormObject( $user, RequestContext $context, $formClass = 'PreferencesForm' ) { + static function getFormObject( $user, IContextSource $context, $formClass = 'PreferencesForm' ) { $formDescriptor = Preferences::getPreferences( $user ); $htmlForm = new $formClass( $formDescriptor, $context, 'prefs' ); diff --git a/includes/RequestContext.php b/includes/RequestContext.php index e3a19a3251..298ab275ca 100644 --- a/includes/RequestContext.php +++ b/includes/RequestContext.php @@ -353,14 +353,14 @@ class RequestContext implements IContextSource { abstract class ContextSource implements IContextSource { /** - * @var RequestContext + * @var IContextSource */ private $context; /** - * Get the RequestContext object + * Get the IContextSource object * - * @return RequestContext + * @return IContextSource */ public function getContext() { if ( $this->context === null ) { @@ -372,11 +372,11 @@ abstract class ContextSource implements IContextSource { } /** - * Set the RequestContext object + * Set the IContextSource object * - * @param $context RequestContext + * @param $context IContextSource */ - public function setContext( RequestContext $context ) { + public function setContext( IContextSource $context ) { $this->context = $context; } diff --git a/includes/RevisionList.php b/includes/RevisionList.php index dfb85eee2b..215b663ede 100644 --- a/includes/RevisionList.php +++ b/includes/RevisionList.php @@ -8,7 +8,7 @@ abstract class RevisionListBase { */ var $title; /** - * @var RequestContext + * @var IContextSource */ var $context; @@ -16,10 +16,10 @@ abstract class RevisionListBase { /** * Construct a revision list for a given title - * @param $context RequestContext + * @param $context IContextSource * @param $title Title */ - function __construct( RequestContext $context, Title $title ) { + function __construct( IContextSource $context, Title $title ) { $this->context = $context; $this->title = $title; } diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 0a52d753ad..b943b51b7e 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -57,7 +57,7 @@ class SpecialPage { /** * Current request context - * @var RequestContext + * @var IContextSource */ protected $mContext; @@ -226,12 +226,12 @@ class SpecialPage { * page, and true if it was successful. * * @param $title Title object - * @param $context RequestContext + * @param $context IContextSource * @param $including Bool output is being captured for use in {{special:whatever}} * @return Bool * @deprecated since 1.18 call SpecialPageFactory method directly */ - public static function executePath( &$title, RequestContext &$context, $including = false ) { + public static function executePath( &$title, IContextSource &$context, $including = false ) { return SpecialPageFactory::executePath( $title, $context, $including ); } @@ -592,7 +592,7 @@ class SpecialPage { /** * Sets the context this SpecialPage is executed in * - * @param $context RequestContext + * @param $context IContextSource * @since 1.18 */ public function setContext( $context ) { @@ -602,11 +602,11 @@ class SpecialPage { /** * Gets the context this SpecialPage is executed in * - * @return RequestContext + * @return IContextSource * @since 1.18 */ public function getContext() { - if ( $this->mContext instanceof RequestContext ) { + if ( $this->mContext instanceof IContextSource ) { return $this->mContext; } else { wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" ); diff --git a/includes/SpecialPageFactory.php b/includes/SpecialPageFactory.php index 86c0bceaf5..210c218c34 100644 --- a/includes/SpecialPageFactory.php +++ b/includes/SpecialPageFactory.php @@ -409,12 +409,12 @@ class SpecialPageFactory { * page, and true if it was successful. * * @param $title Title object - * @param $context RequestContext + * @param $context IContextSource * @param $including Bool output is being captured for use in {{special:whatever}} * * @return bool */ - public static function executePath( Title &$title, RequestContext &$context, $including = false ) { + public static function executePath( Title &$title, IContextSource &$context, $including = false ) { wfProfileIn( __METHOD__ ); // @todo FIXME: Redirects broken due to this call @@ -485,11 +485,11 @@ class SpecialPageFactory { * normal request, and then restores them to their previous values after. * * @param $title Title - * @param $context RequestContext + * @param $context IContextSource * * @return String: HTML fragment */ - static function capturePath( Title $title, RequestContext $context ) { + static function capturePath( Title $title, IContextSource $context ) { global $wgOut, $wgTitle, $wgRequest, $wgUser, $wgLang; // Save current globals diff --git a/includes/Wiki.php b/includes/Wiki.php index ca8584bcb1..985d951556 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -29,7 +29,7 @@ class MediaWiki { /** * TODO: fold $output, etc, into this - * @var RequestContext + * @var IContextSource */ private $context; @@ -45,7 +45,7 @@ class MediaWiki { return $old; } - public function __construct( RequestContext $context = null ) { + public function __construct( IContextSource $context = null ) { if ( !$context ) { $context = RequestContext::getMain(); } @@ -256,10 +256,10 @@ class MediaWiki { * * @deprecated in 1.18; use Article::newFromTitle() instead * @param $title Title - * @param $context RequestContext + * @param $context IContextSource * @return Article object */ - public static function articleFromTitle( $title, RequestContext $context ) { + public static function articleFromTitle( $title, IContextSource $context ) { return Article::newFromTitle( $title, $context ); } diff --git a/includes/logging/LogFormatter.php b/includes/logging/LogFormatter.php index 4efda39655..2e86f04f37 100644 --- a/includes/logging/LogFormatter.php +++ b/includes/logging/LogFormatter.php @@ -78,9 +78,9 @@ class LogFormatter { /** * Replace the default context - * @param $context RequestContext + * @param $context IContextSource */ - public function setContext( RequestContext $context ) { + public function setContext( IContextSource $context ) { $this->context = $context; } diff --git a/includes/revisiondelete/RevisionDeleteAbstracts.php b/includes/revisiondelete/RevisionDeleteAbstracts.php index 81d44497c1..dc7af19440 100644 --- a/includes/revisiondelete/RevisionDeleteAbstracts.php +++ b/includes/revisiondelete/RevisionDeleteAbstracts.php @@ -7,7 +7,7 @@ * to wrap bulk update operations. */ abstract class RevDel_List extends RevisionListBase { - function __construct( RequestContext $context, Title $title, array $ids ) { + function __construct( IContextSource $context, Title $title, array $ids ) { parent::__construct( $context, $title ); $this->ids = $ids; } diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 860fd451c6..0bf52ec4a2 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -758,7 +758,7 @@ class UploadForm extends HTMLForm { protected $mMaxFileSize = array(); - public function __construct( array $options = array(), RequestContext $context = null ) { + public function __construct( array $options = array(), IContextSource $context = null ) { $this->mWatch = !empty( $options['watch'] ); $this->mForReUpload = !empty( $options['forreupload'] ); $this->mSessionKey = isset( $options['sessionkey'] ) -- 2.20.1